package com.demo.mockito;

import com.github.benmanes.caffeine.cache.Cache;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
public class CacheTest {

    @Mock
    Cache<String, String> catCache;

    @Test
    public void test() {
        String cacheKey = "1_1000";
        when(catCache.getIfPresent(cacheKey)).thenReturn(null).thenReturn(null).thenReturn("hello");
        Assertions.assertNull(catCache.getIfPresent(cacheKey));
        Assertions.assertNull(catCache.getIfPresent(cacheKey));
        Assertions.assertEquals("hello", catCache.getIfPresent(cacheKey));
    }

}
